package com.wangxinyuchuan.demo.adapter.delegate;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Properties;

/**
 * @author wangxinyuchuan
 * @date 2023/4/9 10:17 PM
 */
public class FileProperties extends Properties implements FileIO {
    @Override
    public void readFromFile(String fileName) throws IOException {
        load(Files.newInputStream(Paths.get(System.getProperty("user.dir") + "/" + fileName)));
    }

    @Override
    public void writeToFile(String fileName) throws IOException {
        store(Files.newOutputStream(Paths.get(System.getProperty("user.dir") + "/" + fileName)), "继承实现适配器模式");
    }

    @Override
    public void setValue(String key, String value) {
        setProperty(key, value);
    }

    @Override
    public String getValue(String key) {
        return getProperty(key);
    }
}
